package com.src.myapplication.ui.view;

import android.graphics.Color;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.src.myapplication.R;
import com.src.myapplication.base.BaseFragment;
import com.src.myapplication.ui.adapter.ZhiBoVAdapter;
import com.src.myapplication.utils.FragmentFactory;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class FragmentZhiBo extends BaseFragment {


    public TabLayout tb;
    public ViewPager vp;

    @Override
    public void initView(View view) {
        tb = (TabLayout) view.findViewById(R.id.tb);
        vp = (ViewPager) view.findViewById(R.id.vp);

        tb.setSelectedTabIndicatorColor(Color.parseColor("#EE554D"));
        //设置指示器高度
        tb.setSelectedTabIndicatorHeight(1);
        //导航模式
        tb.setTabMode(TabLayout.MODE_SCROLLABLE);
        String[] stringArray = getResources().getStringArray(R.array.zhibo_title);

        List<Fragment> data = new ArrayList<>();
        for (int i = 0; i < stringArray.length; i++) {
            Fragment fragment = FragmentFactory.createFragment(i);
            data.add(fragment);
        }
        ZhiBoVAdapter adapter = new ZhiBoVAdapter(getFragmentManager(), stringArray, data);
        vp.setOffscreenPageLimit(2);
        tb.setupWithViewPager(vp);
        vp.setAdapter(adapter);
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_zhibo;
    }

}
